home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / Halma 1.1.source Folder / Halma ƒ / Shell ƒ / about MSG.c next >
Encoding:
C/C++ Source or Header  |  1994-05-23  |  6.9 KB  |  254 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        about MSG.c
  4.  
  5. Purpose:    This module handles displaying the "About MSG" splash
  6.             screen.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "graphics.h"        /* needs to come first because it defines WindowDataHandle */
  26. #include "about MSG.h"
  27. #include "environment.h"
  28. #include "sounds.h"
  29.  
  30. extern Point RawMouse : 0x82C;
  31.  
  32. /*-----------------------------------------------------------------------------------*/
  33. /* internal stuff for about MSG.c                                                    */
  34.  
  35. void SetupTheAboutMSGWindow(WindowDataHandle theData);
  36. void OpenTheMSGWindow(WindowDataHandle theData);
  37. void DrawTheAboutMSGWindow(void);
  38. void DoTheMSGThing(WindowDataHandle theData);
  39. void ActivateTheMSGWindow(void);
  40. void DeactivateTheMSGWindow(WindowDataHandle theData);
  41. void GetTheNextLine(Handle textHandle, unsigned long theSize, unsigned long *pos, Str255 theLine);
  42. void DrawTheAboutString(Str255 theString, short theWidth, short *theRow);
  43. void DrawTheCarpet(void);
  44. void DrawTheString(Str255 theString, short theWidth, short* theRow);
  45. void DrawCarpet(short x, short y, short len);
  46.  
  47. static short        gOldForegroundTime;
  48.  
  49. short AboutMSGBoxDispatch(WindowDataHandle theData, short theMessage, unsigned long misc)
  50. {
  51.     short            theDepth;
  52.     
  53.     switch (theMessage)    /* see graphics.h for list of messages*/
  54.     {
  55.         case kNull:
  56.             if (!gIsInBackground)
  57.                 DoTheMSGThing(theData);
  58.             return kSuccess;
  59.             break;
  60.         case kUpdate:
  61.             DrawTheAboutMSGWindow();
  62.             return kSuccess;
  63.             break;
  64.         case kOpen:
  65.             OpenTheMSGWindow(theData);
  66.             return kSuccess;
  67.         case kActivate:
  68.             ActivateTheMSGWindow();
  69.             return kSuccess;
  70.             break;
  71.         case kDeactivate:
  72.             DeactivateTheMSGWindow(theData);
  73.             return kSuccess;
  74.             break;
  75.         case kKeydown:                            /* close about box on keypress */
  76.         case kMousedown:                        /* or mouseclick */
  77.             CloseTheWindow((ExtendedWindowDataHandle)theData);
  78.             return kSuccess;
  79.             break;
  80.         case kStartup:
  81.             SetupTheAboutMSGWindow(theData);
  82.             return kSuccess;
  83.             break;
  84.     }
  85.     
  86.     return kFailure;        /* for all other messages, defer to default processing */
  87. }
  88.  
  89. void SetupTheAboutMSGWindow(WindowDataHandle theData)
  90. {
  91.     (**theData).windowWidth=243;
  92.     (**theData).windowHeight=243;
  93.     (**theData).windowType=plainDBox;        /* plain rectangle */
  94.     (**theData).windowTitle[0]=0x00;        /* null title, never shown */
  95.     (**theData).hasCloseBox=FALSE;
  96.     (**theData).maxDepth=1;
  97. }
  98.  
  99. void OpenTheMSGWindow(WindowDataHandle theData)
  100. {
  101.     long            dummy;
  102.     
  103.     DoSound(sound_aboutMSG, TRUE);
  104.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  105.     Delay(30, &dummy);
  106. }
  107.  
  108. void ActivateTheMSGWindow(void)
  109. {
  110.     gOldForegroundTime=gForegroundWaitTime;
  111.     gForegroundWaitTime=0;
  112. }
  113.  
  114. void DeactivateTheMSGWindow(WindowDataHandle theData)
  115. {
  116.     UpdateTheWindow((ExtendedWindowDataHandle)theData);
  117.     gForegroundWaitTime=gOldForegroundTime;
  118. }
  119.  
  120. void DoTheMSGThing(WindowDataHandle theData)
  121. {
  122.     Rect            sourceRect, destRect;
  123.     Rect            mainRect;
  124.     long            lr,tb;
  125.     short            l,t;
  126.     short            index;
  127.     
  128.     index=(**theData).windowIndex;
  129.     mainRect=screenBits.bounds;
  130.     if (PtInRect(RawMouse, &mainRect))
  131.     {
  132.         lr=RawMouse.h-mainRect.left;
  133.         lr*=81;
  134.         lr/=mainRect.right-mainRect.left;
  135.         tb=RawMouse.v-mainRect.top;
  136.         tb*=81;
  137.         tb/=mainRect.bottom-mainRect.top;
  138.         if (tb<0)
  139.             tb=0;
  140.         l=RawMouse.h-lr;
  141.         t=RawMouse.v-tb;
  142.         SetRect(&sourceRect, l, t, l+81, t+81);
  143.         SetRect(&destRect, 81, 81, 162, 162);
  144.         SetPort(gTheWindow[index]);
  145.         CopyBits(&(WMgrPort->portBits), &(gTheWindow[index]->portBits),
  146.             &sourceRect, &destRect, 0, 0L);
  147.     }
  148. }
  149.  
  150. void DrawTheAboutMSGWindow(void)
  151. {
  152.     short            row;
  153.     Rect            sourceRect, destRect;
  154.     GrafPtr            curPort;
  155.     short            theWidth;
  156.     
  157.     GetPort(&curPort);
  158.     EraseRect(&(curPort->portRect));
  159.     theWidth=curPort->portRect.right-curPort->portRect.left;
  160.     
  161.     DrawCarpet(9,234,3);
  162.     SetRect(&sourceRect, 0, 216, 27, 243);
  163.     destRect=sourceRect;
  164.     OffsetRect(&destRect, 27, 0);
  165.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  166.         &sourceRect, &destRect, 0, 0L);
  167.     OffsetRect(&destRect, -27, -27);
  168.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  169.         &sourceRect, &destRect, 0, 0L);
  170.     OffsetRect(&destRect, 0, -27);
  171.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  172.         &sourceRect, &destRect, 0, 0L);
  173.     OffsetRect(&destRect, 27, 0);
  174.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  175.         &sourceRect, &destRect, 0, 0L);
  176.     SetRect(&sourceRect, 0, 162, 27, 243);
  177.     destRect=sourceRect;
  178.     OffsetRect(&destRect, 54, 0);
  179.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  180.         &sourceRect, &destRect, 0, 0L);
  181.     SetRect(&sourceRect, 0, 162, 81, 243);
  182.     destRect=sourceRect;
  183.     OffsetRect(&destRect, 81, 0);
  184.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  185.         &sourceRect, &destRect, 0, 0L);
  186.     OffsetRect(&destRect, -81, -81);
  187.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  188.         &sourceRect, &destRect, 0, 0L);
  189.     OffsetRect(&destRect, 0, -81);
  190.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  191.         &sourceRect, &destRect, 0, 0L);
  192.     OffsetRect(&destRect, 81, 0);
  193.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  194.         &sourceRect, &destRect, 0, 0L);
  195.     SetRect(&sourceRect, 0, 0, 81, 243);
  196.     destRect=sourceRect;
  197.     OffsetRect(&destRect, 162, 0);
  198.     CopyBits(&(curPort->portBits), &(curPort->portBits),
  199.         &sourceRect, &destRect, 0, 0L);
  200.     
  201.     TextFont(geneva);
  202.     TextSize(9);
  203.     TextMode(srcXor);
  204.     row=92;
  205.     DrawTheString("\pMerriMac", theWidth, &row);
  206.     DrawTheString("\pSoftware", theWidth, &row);
  207.     DrawTheString("\pGroup ’94", theWidth, &row);
  208.     DrawTheString("\p", theWidth, &row);
  209.     DrawTheString("\pStill enhancing", theWidth, &row);
  210.     DrawTheString("\pthe flavor of", theWidth, &row);
  211.     DrawTheString("\pyour Macintosh.", theWidth, &row);
  212. }
  213.  
  214. void DrawTheString(Str255 theString, short theWidth, short* theRow)
  215. {
  216.     MoveTo((theWidth-StringWidth(theString))/2, *theRow);
  217.     DrawString(theString);
  218.     *theRow+=11;
  219. }
  220.  
  221. void DrawCarpet(short x, short y, short len)
  222. {
  223.     Rect            box;
  224.     short            iter;
  225.  
  226.     x-=len*2;
  227.     y+=len*2;
  228.     for (iter=0; iter<8; iter++)
  229.     {
  230.         box.left=x-len;
  231.         box.right=x+2*len;
  232.         box.top=y-2*len;
  233.         box.bottom=y+len;
  234.         FillRect(&box, black);
  235.         if (len>1) DrawCarpet(x,y,len/3);
  236.         box.left=x;
  237.         box.right=x+len;
  238.         box.bottom=y;
  239.         box.top=y-len;
  240.         FillRect(&box, white);
  241.         switch (iter)
  242.         {
  243.             case 0:
  244.             case 1: x+=len*3; break;
  245.             case 2:
  246.             case 3: y-=len*3; break;
  247.             case 4:
  248.             case 5: x-=len*3; break;
  249.             case 6:
  250.             case 7: y+=len*3; break;
  251.         }
  252.     }
  253. }
  254.